package com.adcc.swingui.demo;

import java.awt.HeadlessException;

import javax.swing.JFrame;

import org.apache.log4j.PropertyConfigurator;

import com.adcc.swingui.DefaultFrameUi;
import com.adcc.swingui.bean.PanelBean;
import com.adcc.swingui.conf.MenuBarConf;
import com.adcc.swingui.conf.MenuRightBarConf;
import com.adcc.swingui.conf.PanelConf;
import com.adcc.swingui.conf.StatusBarConf;
import com.adcc.swingui.conf.SystemSetConf;
import com.adcc.swingui.conf.ToolBarConf;
import com.adcc.swingui.factory.MenuBarFactory;
import com.adcc.swingui.factory.MenuRightFactory;
import com.adcc.swingui.factory.PanelFactory;
import com.adcc.swingui.factory.StatusBarFactory;
import com.adcc.swingui.factory.ToolBarFactory;
import com.jidesoft.plaf.LookAndFeelFactory;
/**
 * 测试主函数
 * @author charlie
 *
 */
public class DemoUi extends DefaultFrameUi {
	
	public static final long serialVersionUID = 1L;
	
	private static PanelBean panelBean = null;

	public DemoUi(String title) throws HeadlessException {
		super(title);
	}
	
    public static void main(String[] args) {
    	// 加载日志配置
    	PropertyConfigurator.configure(System.getProperty("user.dir") + "/conf/log4j.properties");

        // set the L&F and add additional UIDefaults for JIDE components
        LookAndFeelFactory.installDefaultLookAndFeelAndExtension();

        DefaultFrameUi frame = new DemoUi("skymeteo");
        String panelXml = "conf/default/panel.xml";
    	String panelName = "panel1";
    	
        frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
        try {
        	 //加载配置
            PanelConf.initConf(panelXml);
            panelBean = PanelConf.getPanelConf().get(panelName);
            ToolBarConf.initConf(panelBean.getToolBarConf());
            MenuBarConf.initConfNew(panelBean.getMenuBarConf());
            StatusBarConf.initConf(panelBean.getStatusBarConf());
            SystemSetConf.initConf(panelBean.getSystemSetConf());
            MenuRightBarConf.initConf(panelBean.getMenuRightBarConf());
            
            // TODO: change args[0] to the location of initial layout file
            frame.loadInitialLayout(panelBean.getLayoutConf());
            frame.getLayoutPersistence().loadLayoutData();
            frame.toFront();
            
            //根据配置创建控件
            PanelFactory.create(new String[]{panelName}, frame);
            ToolBarFactory.create(panelBean.getToolBar(), frame);
            MenuBarFactory.createNew(panelBean.getMenuBar(), frame);
            StatusBarFactory.create(panelBean.getStatusBar(), frame);
            MenuRightFactory.create(panelBean.getMenuRightBar(), frame);
        }
        catch (Exception e) {
            e.printStackTrace();
        }
    }

	public static PanelBean getPanelBean() {
		return panelBean;
	}

}
